
<script type="text/javascript" src="<?= $this->config->base_url(); ?>assets/js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="<?= $this->config->base_url(); ?>assets/js/jquery-ui.js"></script>
<link rel="stylesheet" href="<?= $this->config->base_url(); ?>assets/css/jquery-ui.css" type="text/css" charset="utf-8" />

<script>
function get_productname(product_name){
	var x = product_name.length
	if(x < 5){
		$('#product_list').show()
		$('#product_list').html("search field must content minimum 4 Character")
	
	}else{
		$.post('<?= site_url('autocomplete/get_product')?>', { product_name : product_name },function(msg){
		if(msg){
		$('#product_list').show()
		$('#product_list').html(msg)
		x = 0
		}		
		})
		
	}
}

function get_productname1(product_name,x){
	var l = product_name.length
	if(l<4){
		var product_list  = '#product_list'+x
		$(product_list).show()
		$(product_list).html('Search Field Must content atleast 4 character!')
	}else{
		$.post('<?= site_url('autocomplete/get_product1')?>', { product_name : product_name, counter:x },function(msg){
	if(msg){
		var product_list  = '#product_list'+x
		$(product_list).show()
		$(product_list).html(msg)
		l = 0
		
	}		
		
	})

	}
	
}

</script>
<script>

function get( quantity){
    var branch=$('#source_branch').val();
    var code=$('#item_code').val();
	$.post("<?= site_url('product/transfer/check_branch_product')?>",{ branch:branch, code:code , quantity:quantity }, function(msg){
	if(msg==1){
	$.post("<?= site_url('product/transfer/get_destination_branch')?>",{ branch:branch }, function(msg1){
	if(msg1){
				jQuery('#areas').empty().append(msg1);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

		}
	});
	}else if(msg==2){
		alert('Required Quantity Not Available!!')
	}else if(msg==3){
		alert('Required Product is Not Available!!')
		
	}
	
	
	})

}
function get1( quantity,x){
    var branch=$('#source_branch').val();
    var codes='#item_code'+x
	
    var code=$(codes).val();
	alert(code);
	alert(branch);
	alert(quantity);
	$.post("<?= site_url('product/transfer/check_branch_product')?>",{ branch:branch, code:code , quantity:quantity }, function(msg){
	if(msg==1){
	$.post("<?= site_url('product/transfer/get_destination_branch')?>",{ branch:branch }, function(msg1){
	if(msg1){
				jQuery('#areas').empty().append(msg1);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

		}
	});
	}else if(msg==2){
		alert('Required Quantity Not Available!!')
	}else if(msg==3){
		alert('Required Product is Not Available!!')
		
	}
	
	
	})

}
function set_product(code){ 
var product_name = '#unique'+code
var product_code = '#cod'+code
var code_r = $(product_code).val()
var name = $(product_name).val()


$('#item_name').val(name)	;
$('#item_code').val(code_r)
$('#product_list').hide()	

}
function set_product1(code,counter){
var unique_name = '#unique'+code 
var product_code = '#cod'+code
var code_r = $(product_code).val()
var name = $(unique_name).val()
var product_name = '#item_name'+counter
var code_field =  '#item_code'+counter
var product_list = '#product_list'+counter
var col_rate = '#rate'+counter
$(product_name).val(name)	
$(code_field).val(code_r)
$(product_list).hide()	
}

</script>
<script>

$(function() {
        var scntDiv = $('#p_scents');
        var i = $('#p_scents tr').size() + 1;
     $('.addScnt').live('click', function() {
                $('<tr id="dd'+ i +'"> <td><input type="text" class="span8"  name="item_name[]"  oninput="get_productname1(this.value,'+i+')"  id="item_name'+i+'" /><div   style="height: 200px; width:380px; cursor:pointer; overflow-y: scroll; word-wrap: normal; display:none " id="product_list'+i+'"</td>  <td><input type="text" class="span8" name="item_code[]" id="item_code'+i+'" /></td><td><input type="text" class="span8"  name="quantity[]" id="quantity'+i+'" /></td> <td><a href="#" class="addScnt">ADD</a>&nbsp;&nbsp;&nbsp;<a href="#" id="'+i+'" class="remScnt">Remove</a></td></tr>').appendTo(scntDiv);
                i++;
				
                return false;
        });
        
        $('.remScnt').live('click', function() { 
       	
	            if( i > 2 ) {
                        
						$(this).parents('tr').remove();
                        i--;
                }
                return false;
		
        });
});










</script>
<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:5px;">Update Transfer </h2>
<br>
<br>

<form method="post" action="<?php  site_url('product/transfer/edit_transfer_order/$id')?>">
<table align="center">
<tr>
<td><strong>SOURCE BRANCH</strong></td>
<td><select name="source_branch" id="source_branch" class="chzn-select">
    			<option value="">-- Select-- </option>
				   <?php foreach ($branches as $branch) {?>
			  
    <option value="<?=$branch->id?>" <?php 
	if($transfer->source_branch == $branch->id)
	{
		echo 'selected = "selected"';
	}
	
	?> ><?= $branch->name;?></option >
    <?php } ?>
    		</select>
			   
		
		</td>


<tr>
<td><strong>DESTINATION BRANCH<strong></td>
<td><select name="destination_branch" id="destination_branch"class="chzn-select">
    			<option value="">-- Select-- </option>
				
			    <?php foreach ($branches as $branch) {?>
			  
    <option value="<?=$branch->id?>" <?php 
	if($transfer->destination_branch == $branch->id)
	{
		echo 'selected = "selected"';
	}
	
	?> ><?= $branch->name;?></option >
    <?php } ?>
    		</select>
		</td>

       </tr>

<tr><td><strong>TRANSFER ID</strong>
<td><?php echo form_input($transfer_id);?></td></tr>
</tr>  
<tr>      
<td><strong> DATE:</strong></td>
<td><?php echo form_input($date);?></td></td>
</tr>
</table>

<hr>
<hr>
<div class="row-fluid">





<div class="span12 pad_all">
<table width="100%" class="table table-bordered" >
  <tr class="info">
               <td><b>ITEM NAME</b></td>
               <td><b>ITEM CODE</b></td>
			  <td><b>QUANTITY</b></td>
              <td><b>OPTIONS</b></td>
             </tr>
			
 <tbody id="p_scents">     
<?php foreach ($transfer_product as $transfer ){?> 
  <tr>
  <label for="p_scnts">
    <td><input type="text" class="span8" name='item_name[]' id="item_name" value="<?php echo $transfer->name;?>" oninput="get_productname(this.value)" /><div   style="height: 200px; width:380px; cursor:pointer; overflow-y: scroll; word-wrap: normal; display:none " id="product_list"></div></td>
    <td><input type="text" class="span8" value=" <?php echo $transfer->code;?>" name="item_code[]" id="item_code"  /></td>
	 <td><input type="text" class="span8"  id="quantity" value="<?php echo $transfer->quantity;?>" name='quantity[]'/></td>
  <td><a href="#" class="addScnt">ADD</a></td>
 </label> </tr>
 <?php } ?>
  </tbody>
</table>
<br>
<br>
<p align="right"><?php echo form_submit('submit', 'update', 'class="btn btn-info"');?></p>

</div>
</div></form>
<script>


$(document).ready(function(){
	$('#date').datepicker({ dateFormat: 'yy-mm-dd' });
	
	
})

</script>